package #(package);

import #(servicePackageName)Service;
import com.juran.common.util.IResponse;
import com.juran.common.util.PageResult;
import com.lianheng.cms.common.dto.BaseSearchDto;
import #(modelPackageName);
import #(dtoPackageName)Dto;
import lombok.extern.slf4j.Slf4j;
import lombok.Getter;
import lombok.Setter;
import org.springframework.http.ResponseEntity;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
/**
* #(className) 管理
* 描述：
*
*/
@Slf4j
@RestController
@RequestMapping("/#(classNameSmall)")
public class #(className)Controller implements IResponse  {


    @Autowired
    #(className)Service #(classNameSmall)Service;

        /**
        * #(classNameSmall)列表
        */
        @PostMapping("/list")
        public ResponseEntity<PageResult> #(classNameSmall)List(BaseSearchDto searchDto) {
            PageResult pageList =#(classNameSmall)Service.#(classNameSmall)Paginate(searchDto);
            return ok(pageList);
        }

        /**
        * 保存#(classNameSmall)
        */
        @PostMapping("/save")
        public ResponseEntity<#(className)Dto> #(classNameSmall)Save(#(className)Dto #(classNameSmall)Dto) {
            #(className) #(classNameSmall) = new #(className)();
            BeanUtils.copyProperties(#(classNameSmall)Dto, #(classNameSmall));
            #(classNameSmall)Service.#(classNameSmall)Save(#(classNameSmall));
            return ok(#(classNameSmall));

        }


        /**
        * 更新#(classNameSmall)
        */
        @PostMapping("/edit")
        public ResponseEntity<#(className)Dto> #(classNameSmall)Update(#(className)Dto #(classNameSmall)Dto) {
             #(className) #(classNameSmall) = new #(className)();
             BeanUtils.copyProperties(#(classNameSmall)Dto, #(classNameSmall));
             #(classNameSmall)Service.#(classNameSmall)Update(#(classNameSmall));
             return ok(#(classNameSmall));
        }

        /**
        * 查看#(classNameSmall)
        */
        @PostMapping("/get")
        public ResponseEntity<#(className)Dto> #(classNameSmall)View(Long id) {
            return ok(#(classNameSmall)Service.#(classNameSmall)FindById(id));
        }

        /**
        * 删除
        * /#(basePath)/#(classNameSmall)/delete
        */
        @PostMapping("/del")
        public ResponseEntity #(classNameSmall)Delete(Long id) {
            #(classNameSmall)Service.#(classNameSmall)Delete(id);
            return ok();
        }

}